package com.sunfeng.n3;

import com.sunfeng.TimeUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * 打断正常执行的线程
 *
 * @author sunfeng
 * @date 2021/03/16 17:04
 **/

@Slf4j(topic = "c.Test12")
public class Test12 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {

            /**
             * 这个没有 暂停，没有抛出异常
             */
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    log.debug("线程被打断了");
                    break;
                }
            }
        }, "t1");


        t1.start();
        TimeUtils.sleep(1);
        t1.interrupt();
        log.info("线程t1的打断标记为{}", t1.isInterrupted());

    }
}
